/**
* 左边菜单
*/
<template>
  <el-menu default-active="2" :collapse="collapsed" collapse-transition router :default-active="$route.path"
    unique-opened class="el-menu-vertical-demo" background-color="#334157" text-color="#fff"
    active-text-color="#ffd04b">
    <div class="logobox">
      <img class="logoimg" src="../assets/img/logo.png" alt="">
    </div>
    <el-submenu v-for="menu in allmenu" :key="menu.menuid" :index="menu.menuname">
      <template slot="title">
        <i class="iconfont" :class="menu.icon"></i>
        <span v-if="menu.menuname === '财务管理'">{{ menu.menuname }} <i style="color: red; padding-left: 10px;"
            v-if="TixianCount != 0">{{
    TixianCount }}</i></span>
        <span v-else-if="menu.menuname === '合伙人管理'">{{ menu.menuname }} <i style="color: red; padding-left: 10px;"
            v-if="HehuoCount != 0">{{
    HehuoCount }}</i></span>
        <span v-else-if="menu.menuname === '用户反馈'">{{ menu.menuname }} <i style="color: red; padding-left: 10px;"
            v-if="FeedbackCount != 0">{{
    FeedbackCount }}</i></span>
        <span v-else-if="menu.menuname === '发票管理'">{{ menu.menuname }} <i style="color: red; padding-left: 10px;"
            v-if="InvoiceCount != 0">{{
    InvoiceCount }}</i></span>
        <span v-else-if="menu.menuname === '充电桩管理'">{{ menu.menuname }} <i style="color: red; padding-left: 10px;"
            v-if="WarnCount != 0 || StationCount != 0 || SiteCount != 0">{{
    WarnCount + StationCount + SiteCount }}</i></span>
        <span v-else-if="menu.menuname === '转让管理'">{{ menu.menuname }} <i style="color: red; padding-left: 10px;"
            v-if="TransferStationCount != 0 || VenuesCount != 0">{{
    TransferStationCount + VenuesCount }}</i></span>
        <span v-else>{{ menu.menuname }}</span>
      </template>
      <el-menu-item-group>
        <el-menu-item v-for=" chmenu  in menu.menus" :index="'/' + chmenu.url" :key="chmenu.menuid">
          <i class="iconfont" :class="chmenu.icon"></i>
          <span v-if="chmenu.menuname === '提现管理'">{{ chmenu.menuname }} <i style="color: red; padding-left: 10px;"
              v-if="TixianCount != 0">{{
    TixianCount }}</i></span>
          <span v-else-if="chmenu.menuname === '合伙人申请列表'">{{ chmenu.menuname }} <i
              style="color: red; padding-left: 10px;" v-if="HehuoCount != 0">{{
    HehuoCount }}</i></span>
          <span v-else-if="chmenu.menuname === '用户反馈列表'">{{ chmenu.menuname }} <i
              style="color: red; padding-left: 10px;" v-if="FeedbackCount != 0">{{
    FeedbackCount }}</i></span>
          <span v-else-if="chmenu.menuname === '发票列表'">{{ chmenu.menuname }} <i style="color: red; padding-left: 10px;"
              v-if="InvoiceCount != 0">{{
    InvoiceCount }}</i></span>
          <span v-else-if="chmenu.menuname === '警告管理'">{{ chmenu.menuname }} <i style="color: red; padding-left: 10px;"
              v-if="WarnCount != 0">{{
    WarnCount }}</i></span>
          <span v-else-if="chmenu.menuname === '充电桩管理'">{{ chmenu.menuname }} <i style="color: red; padding-left: 10px;"
              v-if="StationCount != 0">{{
    StationCount }}</i></span>
          <span v-else-if="chmenu.menuname === '站点管理'">{{ chmenu.menuname }} <i style="color: red; padding-left: 10px;"
              v-if="SiteCount != 0">{{
    SiteCount }}</i></span>
          <span v-else-if="chmenu.menuname === '充电桩转让列表'">{{ chmenu.menuname }} <i
              style="color: red; padding-left: 10px;" v-if="TransferStationCount != 0">{{
    TransferStationCount }}</i></span>
          <span v-else-if="chmenu.menuname === '场地转让列表'">{{ chmenu.menuname }} <i
              style="color: red; padding-left: 10px;" v-if="VenuesCount != 0">{{
              VenuesCount }}</i></span>
          <span v-else>{{ chmenu.menuname }}</span>
        </el-menu-item>
      </el-menu-item-group>
    </el-submenu>

    <!-- 输入密码对话框 -->
    <!-- <el-dialog title="输入密码" :visible.sync="dialogVisible" width="30%">
      <el-input type="password" v-model="password" autocomplete="off"></el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleSubmit">确 定</el-button>
      </span>
    </el-dialog> -->

  </el-menu>
</template>
<script>
import { menu } from '../api/userMG'
import {
  getWaitPayoutsCount,
  getWaitAduitChargerOwnerCount,
  getWaitFeedbackCount,
  getWaitInvoiceCount,
  getWaitWarnCount,
  getWaitAduitSiteCount,
  getWaitAduitStationCount,
  getWaitAduitTransferStationCount,
  getWaitAduitVenuesCount,
} from "../api/userMG";
export default {
  name: 'leftnav',
  data() {
    return {
      collapsed: false,
      allmenu: [],
      TixianCount: '',
      HehuoCount: '',
      FeedbackCount: '',
      InvoiceCount: '',
      WarnCount: '',
      SiteCount: '',
      StationCount: '',
      TransferStationCount: '',
      VenuesCount: '',
      password: '',
      dialogVisible: false,
    }
  },
  // 创建完毕状态(里面是操作)
  created() {
    this.getCount()

    // 获取图形验证码
    let res = {
      success: true,
      data: [
        {
          menuid: 1,
          icon: 'li-icon-xiangmuguanli',
          menuname: '首页',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 11,
              icon: 'icon-cat-skuQuery',
              menuname: '首页',
              hasThird: 'N',
              url: 'index/Index',
              menus: null,
            },
            {
              menuid: 12,
              icon: 'icon-cat-skuQuery',
              menuname: '数据统计',
              hasThird: 'N',
              url: 'index/DataStatistics',
              menus: null
            }
          ],
        },
        {
          menuid: 2,
          icon: 'li-icon-xiangmuguanli',
          menuname: '用户管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 21,
              icon: 'icon-cat-skuQuery',
              menuname: '用户列表',
              hasThird: 'N',
              url: 'user/User',
              menus: null
            }
          ]
        },
        {
          menuid: 3,
          icon: 'li-icon-xiangmuguanli',
          menuname: '合伙人管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 31,
              icon: 'icon-cat-skuQuery',
              menuname: '合伙人列表',
              hasThird: 'N',
              url: 'partner/Partner',
              menus: null
            },
            {
              menuid: 32,
              icon: 'icon-cat-skuQuery',
              menuname: '合伙人申请列表',
              hasThird: 'N',
              url: 'partner/PartnerApplication',
              menus: null
            }
          ]
        },
        {
          menuid: 4,
          icon: 'li-icon-xiangmuguanli',
          menuname: '充电桩管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 41,
              icon: 'icon-cat-skuQuery',
              menuname: '充电桩管理',
              hasThird: 'N',
              url: 'chargingStation/ElectricPile',
              menus: null
            },
            {
              menuid: 42,
              icon: 'icon-cat-skuQuery',
              menuname: '站点管理',
              hasThird: 'N',
              url: 'chargingStation/Site',
              menus: null
            },
            {
              menuid: 43,
              icon: 'icon-cat-skuQuery',
              menuname: '端口管理',
              hasThird: 'N',
              url: 'chargingStation/Port',
              menus: null
            },
            {
              menuid: 44,
              icon: 'icon-cat-skuQuery',
              menuname: '充电桩订单管理',
              hasThird: 'N',
              url: 'chargingStation/OrderForGoods',
              menus: null
            },
            {
              menuid: 45,
              icon: 'icon-cat-skuQuery',
              menuname: '警告管理',
              hasThird: 'N',
              url: 'chargingStation/Warn',
              menus: null
            },
            {
              menuid: 46,
              icon: 'icon-cat-skuQuery',
              menuname: '余额充电金额终止条件',
              hasThird: 'N',
              url: 'chargingStation/Termination',
              menus: null
            },
          ]
        },
        {
          menuid: 16,
          icon: 'li-icon-xiangmuguanli',
          menuname: '管理员充电桩管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 161,
              icon: 'icon-cat-skuQuery',
              menuname: '管理员充电桩列表',
              hasThird: 'N',
              url: 'adminCharging/AdminElctricPile',
              menus: null
            },
            {
              menuid: 162,
              icon: 'icon-cat-skuQuery',
              menuname: '管理员站点列表',
              hasThird: 'N',
              url: 'adminCharging/AdminSite',
              menus: null
            },
            {
              menuid: 163,
              icon: 'icon-cat-skuQuery',
              menuname: '管理员端口列表',
              hasThird: 'N',
              url: 'adminCharging/AdminPort',
              menus: null
            },
          ]
        },
        {
          menuid: 5,
          icon: 'li-icon-xiangmuguanli',
          menuname: '发票管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 51,
              icon: 'icon-cat-skuQuery',
              menuname: '发票列表',
              hasThird: 'N',
              url: 'invoice/Invoice',
              menus: null
            }
          ]
        },
        {
          menuid: 6,
          icon: 'li-icon-xiangmuguanli',
          menuname: '商品管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 61,
              icon: 'icon-cat-skuQuery',
              menuname: '商品分类列表',
              hasThird: 'N',
              url: 'commodity/Category',
              menus: null
            },
            {
              menuid: 62,
              icon: 'icon-cat-skuQuery',
              menuname: '商品列表',
              hasThird: 'N',
              url: 'commodity/Commodity',
              menus: null
            },
            {
              menuid: 63,
              icon: 'icon-cat-skuQuery',
              menuname: '订单列表',
              hasThird: 'N',
              url: 'commodity/ProductOrders',
              menus: null
            },
            {
              menuid: 64,
              icon: 'icon-cat-skuQuery',
              menuname: '评论列表',
              hasThird: 'N',
              url: 'commodity/Comment',
              menus: null
            },
          ]
        },
        {
          menuid: 13,
          icon: 'li-icon-xiangmuguanli',
          menuname: '优惠券管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 131,
              icon: 'icon-cat-skuQuery',
              menuname: '充电桩优惠券',
              hasThird: 'N',
              url: 'coupon/FullReduction',
              menus: null
            },
            {
              menuid: 132,
              icon: 'icon-cat-skuQuery',
              menuname: '商城优惠券',
              hasThird: 'N',
              url: 'coupon/MallCoupons',
              menus: null
            },
            {
              menuid: 133,
              icon: 'icon-cat-skuQuery',
              menuname: '活动优惠券',
              hasThird: 'N',
              url: 'coupon/EventCoupons',
              menus: null
            },
            {
              menuid: 134,
              icon: 'icon-cat-skuQuery',
              menuname: '注册赠送优惠券',
              hasThird: 'N',
              url: 'coupon/GiftCoupons',
              menus: null
            },
          ]
        },
        {
          menuid: 7,
          icon: 'li-icon-xiangmuguanli',
          menuname: '财务管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 71,
              icon: 'icon-cat-skuQuery',
              menuname: '积分管理',
              hasThird: 'N',
              url: 'finance/Integral',
              menus: null
            },
            {
              menuid: 77,
              icon: 'icon-cat-skuQuery',
              menuname: '消费反积分百分比管理',
              hasThird: 'N',
              url: 'finance/Consumption',
              menus: null,
              pwd: 123,
            },
            {
              menuid: 72,
              icon: 'icon-cat-skuQuery',
              menuname: '钱包管理',
              hasThird: 'N',
              url: 'finance/Wallet',
              menus: null
            },
            {
              menuid: 73,
              icon: 'icon-cat-skuQuery',
              menuname: '提现管理',
              hasThird: 'N',
              url: 'finance/CashWithdrawal',
              menus: null
            },
            {
              menuid: 78,
              icon: 'icon-cat-skuQuery',
              menuname: '提现税率管理',
              hasThird: 'N',
              url: 'finance/TaxRate',
              menus: null
            },
            {
              menuid: 74,
              icon: 'icon-cat-skuQuery',
              menuname: '充值记录',
              hasThird: 'N',
              url: 'finance/RechargeRecords',
              menus: null
            },
            {
              menuid: 75,
              icon: 'icon-cat-skuQuery',
              menuname: '充值金额设置',
              hasThird: 'N',
              url: 'finance/RechargeAmount',
              menus: null
            },
            {
              menuid: 76,
              icon: 'icon-cat-skuQuery',
              menuname: '充值积分百分比管理',
              hasThird: 'N',
              url: 'finance/RechargePoints',
              menus: null
            },
          ]
        },
        {
          menuid: 8,
          icon: 'li-icon-xiangmuguanli',
          menuname: '会员配置管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 81,
              icon: 'icon-cat-skuQuery',
              menuname: '会员配置列表',
              hasThird: 'N',
              url: 'member/Member',
              menus: null
            }, {
              menuid: 111,
              icon: 'icon-cat-skuQuery',
              menuname: '复购佣金设置',
              hasThird: 'P',
              url: 'laxin/Laxin',
              menus: null
            },
            {
              menuid: 82,
              icon: 'icon-cat-skuQuery',
              menuname: '税金设置',
              hasThird: 'N',
              url: 'member/Taxes',
              menus: null
            },
          ]
        },
        {
          menuid: 9,
          icon: 'li-icon-xiangmuguanli',
          menuname: '设备管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 91,
              icon: 'icon-cat-skuQuery',
              menuname: '设备列表',
              hasThird: 'N',
              url: 'device/Device',
              menus: null
            }
          ]
        },
        {
          menuid: 10,
          icon: 'li-icon-xiangmuguanli',
          menuname: '用户反馈',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 101,
              icon: 'icon-cat-skuQuery',
              menuname: '用户反馈列表',
              hasThird: 'N',
              url: 'feedback/Feedback',
              menus: null
            },
          ]
        },
        {
          menuid: 15,
          icon: 'li-icon-xiangmuguanli',
          menuname: '转让管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 151,
              icon: 'icon-cat-skuQuery',
              menuname: '充电桩转让列表',
              hasThird: 'P',
              url: 'transferReview/TransferReview',
              menus: null
            },
            {
              menuid: 152,
              icon: 'icon-cat-skuQuery',
              menuname: '场地转让列表',
              hasThird: 'P',
              url: 'transferReview/TransferReviewCD',
              menus: null
            },
            {
              menuid: 153,
              icon: 'icon-cat-skuQuery',
              menuname: '转让手续费设置管理',
              hasThird: 'P',
              url: 'transference/Transference',
              menus: null
            },
          ]
        },
        {
          menuid: 20,
          icon: 'li-icon-xiangmuguanli',
          menuname: '排行榜管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 201,
              icon: 'icon-cat-skuQuery',
              menuname: '减碳达人排行榜管理',
              hasThird: 'N',
              url: 'charts/CarbonReduction',
              menus: null
            },
            {
              menuid: 202,
              icon: 'icon-cat-skuQuery',
              menuname: '明日之星排行榜管理',
              hasThird: 'N',
              url: 'charts/Stars',
              menus: null
            },
          ]
        },
        {
          menuid: 14,
          icon: 'li-icon-xiangmuguanli',
          menuname: '平台管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 141,
              icon: 'icon-cat-skuQuery',
              menuname: '轮播图列表',
              hasThird: 'N',
              url: 'terrace/Carousel',
              menus: null
            },
            {
              menuid: 142,
              icon: 'icon-cat-skuQuery',
              menuname: '协议列表',
              hasThird: 'N',
              url: 'terrace/Agreement',
              menus: null
            },
          ]
        },
        {
          menuid: 21,
          icon: 'li-icon-xiangmuguanli',
          menuname: '管理员管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 211,
              icon: 'icon-cat-skuQuery',
              menuname: '管理员',
              hasThird: 'N',
              url: 'administrators/Administrators',
              menus: null
            }
          ]
        },
      ],
      msg: 'success'
    }

    var userdata = JSON.parse(localStorage.getItem("userdata"))
    if (userdata.rolesId == "1") {
      // let data = res.data.filter((sel) => sel.menuid !== 21);
      let data = JSON.parse(userdata.menuIds)
      this.allmenu = data
    } else {
      this.allmenu = res.data
    }

    // 监听
    this.$root.Bus.$on('toggle', value => {
      this.collapsed = !value
    })
  },
  methods: {
    // 获取各个待处理的数量
    getCount() {
      // 获取待提现记录总数
      getWaitPayoutsCount().then((res) => {
        this.loading = false;
        if (res.code != 200) {
          this.$Message({
            type: "info",
            message: res.msg,
          });
        } else {
          this.TixianCount = res.data.count;
          return;
        }
      })
      // 获取合伙人待审核的总数
      getWaitAduitChargerOwnerCount().then((res) => {
        this.loading = false;
        if (res.code != 200) {
          this.$Message({
            type: "info",
            message: res.msg,
          });
        } else {
          this.HehuoCount = res.data.count;
          return;
        }
      })
      // 获取反馈待审核的总数
      getWaitFeedbackCount().then((res) => {
        this.loading = false;
        if (res.code != 200) {
          this.$Message({
            type: "info",
            message: res.msg,
          });
        } else {
          this.FeedbackCount = res.data.count;
          return;
        }
      })
      // 获取待开票发票总数
      getWaitInvoiceCount().then((res) => {
        this.loading = false;
        if (res.code != 200) {
          this.$Message({
            type: "info",
            message: res.msg,
          });
        } else {
          this.InvoiceCount = res.data.count;
          return;
        }
      })
      // 获取待处理警告总数
      getWaitWarnCount().then((res) => {
        this.loading = false;
        if (res.code != 200) {
          this.$Message({
            type: "info",
            message: res.msg,
          });
        } else {
          this.WarnCount = res.data.count;
          return;
        }
      })
      // 获取待审核站点总数
      getWaitAduitSiteCount().then((res) => {
        this.loading = false;
        if (res.code != 200) {
          this.$Message({
            type: "info",
            message: res.msg,
          });
        } else {
          this.SiteCount = res.data.data;
          return;
        }
      })
      // 查询待审核充电桩总数
      getWaitAduitStationCount().then((res) => {
        this.loading = false;
        if (res.code != 200) {
          this.$Message({
            type: "info",
            message: res.msg,
          });
        } else {
          this.StationCount = res.data.data;
          return;
        }
      })
      // 查询待审核转让充电桩总数
      getWaitAduitTransferStationCount().then((res) => {
        this.loading = false;
        if (res.code != 200) {
          this.$Message({
            type: "info",
            message: res.msg,
          });
        } else {
          this.TransferStationCount = res.data.count;
          return;
        }
      })
      // 查询待审核场地总数
      getWaitAduitVenuesCount().then((res) => {
        this.loading = false;
        if (res.code != 200) {
          this.$Message({
            type: "info",
            message: res.msg,
          });
        } else {
          this.VenuesCount = res.data.count;
          return;
        }
      })
    },
  }
}
</script>
<style>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 240px;
  min-height: 400px;
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  border: none;
  text-align: left;
}

.el-menu-item-group__title {
  padding: 0px;
}

.el-menu-bg {
  background-color: #1f2d3d !important;
}

.el-menu {
  border: none;
}

.logobox {
  height: 40px;
  line-height: 40px;
  color: #9d9d9d;
  font-size: 20px;
  text-align: center;
  padding: 20px 0px;
}

.logoimg {
  height: 40px;
}
</style>